/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn.images;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;

/**
 * <p>Project: jse2204 - FontDemo
 * <p>Powered by webrx On 2022-09-26 11:39:40
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class FontDemo {
    public static void main(String[] args) throws Exception {
        BufferedImage src = ImageIO.read(new File("c:/abc/g1.jpg"));

        var w = src.getWidth();
        var h = src.getHeight();
        //var i = new BufferedImage(w, h, 2); //2 代码透明图像，目录只有png 操作透明度
        var i = src;
        var g = i.createGraphics();
        //设置线条和文件的，抗锯齿（平滑）
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_DEFAULT);

        //1.白色的文字，特别小
        //g.drawString("Hello world中文字",50,100);

        //g.setColor(Color.RED);
        //g.setFont(new Font("微软雅黑",Font.BOLD,35));
        //g.drawString("Hello world中文字",50,100);
        //


        //g.setColor(new Color(245,245,245,150));
        //g.setFont(new Font("微软雅黑",Font.BOLD,35));
        //g.drawString("Hello world中文字",50,100);

        g.setColor(new Color(255,0,255));
        g.setFont(new Font("微软雅黑",Font.BOLD,36));
        g.drawString("Hello world中文字",51,101);

        g.setColor(new Color(215,215,215,150));
        g.setFont(new Font("微软雅黑",Font.BOLD,36));
        g.drawString("Hello world中文字",52,102);



        g.dispose();
        ImageIO.write(i, "png", new File("iii.png"));

        //画完图，直接打开
        Runtime.getRuntime().exec("cmd /k start iii.png");

    }
}
